package cn.cdqf.web;

import cn.cdqf.bean.TEmp;
import cn.cdqf.bean.TLoginlog;
import cn.cdqf.service.LoginlogService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginlogServlet {

    @Autowired
    private LoginlogService loginlogService;

    @RequestMapping("/queryLoginlog")
    @ResponseBody
    public List<TLoginlog> queryLoginlog(HttpSession session){
        TEmp emp = (TEmp) session.getAttribute("emp");
        String no = emp.getNo();
        List<TLoginlog> tLoginlog = loginlogService.queryLoginlog(no);
        return tLoginlog;
    }

    @RequestMapping("/getUsername")
    @ResponseBody
    public String getUsername(HttpSession session){
        TEmp emp = (TEmp) session.getAttribute("emp");
        String name = emp.getName();
        return name;
    }

    @RequestMapping("/getImages")
    @ResponseBody
    public String getImages(HttpSession session){
        TEmp emp = (TEmp) session.getAttribute("emp");
        String photo = emp.getPhoto();
        return photo;
    }

    @RequestMapping("/getUserInfo")
    @ResponseBody
    public TEmp getUserInfo(HttpSession session){
        TEmp emp = (TEmp) session.getAttribute("emp");
        String no = emp.getNo();
        TLoginlog tLoginlog = loginlogService.queryLastLoginlog(no);
        String createtime = tLoginlog.getCreatetime();
        emp.setLoginTime(createtime);
        System.out.println(emp);
        return emp;
    }
}
